<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    // var arr = ['刘备', '张飞', '关羽'];
    // console.log(arr.join('|'));


    var arr = ['刘备', '张飞', '关羽'];
    var str = '';
    for (var i = 0; i < arr.length; i++) {
      str += arr[i];
      if (i!==(arr.length-1)) {
        str += '|';
      }
    }
    console.log(str);
  </script>
</body>
</html>